#include<iostream>
#include<vector>
#include<queue>
#include<cstring>
#include<cmath>
#include<map>
#include<set>
#include<cstdio>
#include<algorithm>
#define debug(a) cout<<#a<<"="<<a<<endl;
using namespace std;
const int maxn=2e5+1000;
typedef long long LL;
typedef pair<LL,LL> PI;
inline LL read(){LL x=0,f=1;char ch=getchar();	while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}while (isdigit(ch)){x=x*10+ch-48;ch=getchar();}
return x*f;}
struct P{
    LL op,x;
    LL ti;
}th[maxn];
LL cnt[maxn];
multiset<pair<LL,LL>>s;
int main(void){
   	cin.tie(0);std::ios::sync_with_stdio(false);
    LL q;cin>>q;
    for(LL i=1;i<=q;i++){
        LL op1;LL x1=0;cin>>op1;
        if(op1!=3) cin>>x1;
        th[i].op=op1;
        th[i].x=x1;
        th[i].ti=i;
    }
    for(LL i=1;i<=q;i++){
        if(th[i].op==2){
            cnt[1]+=th[i].x;
            cnt[th[i].ti+1]-=th[i].x;
        }
    }
    for(LL i=1;i<=q;i++){
        cnt[i]+=cnt[i-1];
    }
    for(LL i=1;i<=q;i++){
        cout<<cnt[i]<<" ";
    }cout<<endl;
    for(LL i=1;i<=q;i++){
        if(th[i].op==1){
            s.insert({th[i].x,th[i].ti});
        }
        else if(th[i].op==2){
            continue;
        }
        else if(th[i].op==3){
            PI p=(*s.begin());
            auto it=s.begin();
            s.erase(it);
            LL num=p.first;
            num+=cnt[p.second];
            cout<<num<<"\n";
        }
    }
   	return 0;
}
